﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmForumStudy : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected GridView DataGridInfo;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        private int int_0 = 0;
        protected Label labTip;
        private PublicFun publicFun_0 = new PublicFun();
        private string string_0 = "B";
        protected HtmlInputHidden txtRestoreContent;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = "";
            str = this.httpCookie_1.Value;
            string str2 = "../image/boy.gif";
            if (!(this.httpCookie_4.Value == "女"))
            {
                str2 = "../image/boy.gif";
            }
            else
            {
                str2 = "../image/gril.gif";
            }
            string cmdText = "insert into StudyForum(ContentInfo,UserImg,InputUser,RubricID,RubricType) values(@ContentInfo,@UserImg,@InputUser,@RubricID,@RubricType)";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            command.Parameters.Add("@ContentInfo", SqlDbType.Text).Value = this.publicFun_0.CheckString(this.txtRestoreContent.Value);
            command.Parameters.Add("@UserImg", SqlDbType.VarChar, 50).Value = str2;
            command.Parameters.Add("@InputUser", SqlDbType.VarChar, 20).Value = str;
            command.Parameters.Add("@RubricID", SqlDbType.Int).Value = this.int_0;
            command.Parameters.Add("@RubricType", SqlDbType.Char, 1).Value = this.string_0;
            command.ExecuteNonQuery();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            this.txtRestoreContent.Value = "";
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label label1 = (Label) e.Row.FindControl("labUserRestore");
                Label label = (Label) e.Row.FindControl("labDelChild");
                Label label2 = (Label) e.Row.FindControl("labChildID");
                if (this.httpCookie_2 == null)
                {
                    label.Visible = false;
                }
                else if (!(this.httpCookie_2.Value == "C"))
                {
                    label.Visible = false;
                }
                else
                {
                    label.Visible = true;
                    label.Attributes.Add("onclick", "javascript:{if(confirm('确定要删除吗？')==false) return false;}");
                    label.Text = string.Concat(new object[] { "<a href='DelStudyForumInfo.aspx?Flag=", this.string_0, "&RubricID=", this.int_0, "&ID=", label2.Text, "'><font color=red><B>删除</b></font></a>" });
                }
            }
        }

        private void method_0()
        {
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(string.Concat(new object[] { "select * from StudyForum where RubricType='", this.string_0, "' and RubricID=", this.int_0 }), selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "StudyLogInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["StudyLogInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            adapter.Dispose();
            dataSet.Dispose();
            selectConnection.Dispose();
            if (this.DataGridInfo.Rows.Count != 0)
            {
                this.labTip.Visible = false;
            }
            else
            {
                this.labTip.Visible = true;
                this.labTip.Text = "<br><br><font color=red>暂无学习交流信息</font><Br><br>";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_4 = new HttpCookie("ExamUserSex");
            this.httpCookie_4 = base.Request.Cookies["ExamUserSex"];
            this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
            this.string_0 = this.publicFun_0.CheckString(base.Request["Flag"].ToString());
            if ((this.httpCookie_0 != null) && !(this.httpCookie_0.Value == ""))
            {
                this.butDefault.Visible = true;
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
            }
            else
            {
                this.butDefault.Visible = false;
            }
            base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            base.Response.Cache.SetNoStore();
            this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
            if (!base.IsPostBack)
            {
                if (this.publicFun_0.ReturnPaperData() != "Yes")
                {
                    base.Response.Write("<script>alert('此版本暂未授权,请与管理员联系！')</script>");
                }
                else if (this.int_0 != 0)
                {
                    this.method_0();
                }
            }
        }
    }
}

